package cn.com.surker.control.entity;

import cn.com.surker.base.BaseEntity;
import cn.com.surker.base.ExportInter;
import cn.com.surker.excel.ExcelCell;
import cn.com.surker.util.DateUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;

import java.io.Serializable;
import java.util.Date;

import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * <p>
 * 工控机自主生产发货信息
 * </p>
 *
 * @author admin
 * @since 2025-01-06
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("control_invoice")
public class ControlInvoice extends BaseEntity implements ExportInter, Serializable {

	private static final long serialVersionUID = 1L;

	/**
	 * 标识
	 */
	@TableId(value = "id", type = IdType.AUTO)
	private Long id;

	/**
	 * 工程名称
	 */
	@ExcelCell(value = "工程名称", sort = 0)
	private String conName;

	/**
	 * 客户名称
	 */
	@ExcelCell(value = "客户名称", sort = 1)
	private String clientName;

	/**
	 * 施工单位 工控用这个的好像不多
	 */
	@ExcelCell(value = "施工单位", sort = 2)
	private String builder;

	/**
	 * 工地地址
	 */
	@ExcelCell(value = "工地地址", sort = 3)
	private String address;

	/**
	 * 前场工长
	 */
	@ExcelCell(value = "前场工长", sort = 4)
	private String foreman;

	/**
	 * 工地联系人
	 */
	@ExcelCell(value = "工地联系人", sort = 5)
	private String linkMan;

	/**
	 * 工地联系电话
	 */
	@ExcelCell(value = "工地联系电话", sort = 6)
	private String linkPhone;

	/**
	 * 施工部位
	 */
	@ExcelCell(value = "施工部位", sort = 7)
	private String site;

	/**
	 * 强度等级
	 */
	@ExcelCell(value = "强度等级", sort = 8)
	private String strengthName;

	/**
	 * 塌落度
	 */
	@ExcelCell(value = "塌落度", sort = 9)
	private String slumps;

	/**
	 * 特性要求
	 */
	@ExcelCell(value = "特性要求", sort = 10)
	private String tech;

	/**
	 * 浇筑方式
	 */
	@ExcelCell(value = "浇筑方式", sort = 11)
	private String castModel;

	/**
	 * 泵送设备
	 */
	@ExcelCell(value = "泵送设备", sort = 12)
	private String pumpDevice;

	/**
	 * 砂浆方量
	 */
	@ExcelCell(value = "砂浆方量", sort = 13)
	private Double mortarStere;

	/**
	 * 砼方量
	 */
	@ExcelCell(value = "砼方量", sort = 14)
	private Double concreteStere;

	/**
	 * 车号
	 */
	@ExcelCell(value = "车号", sort = 15)
	private String carCode;

	/**
	 * 车次
	 */
	@ExcelCell(value = "车次", sort = 17)
	private Integer totalCar;

	/**
	 * 车牌号
	 */
	@ExcelCell(value = "车牌号", sort = 16)
	private String carNo;

	/**
	 * 调度员
	 */
	@ExcelCell(value = "调度员", sort = 18)
	private String dispatcher;

	/**
	 * 拌台操作员
	 */
	@ExcelCell(value = "拌台操作员", sort = 19)
	private String mixer;

	/**
	 * 生产时间
	 */
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
	@ExcelCell(value = "生产时间", sort = 20, dateFormat = DateUtil.DATE_DETAIL_FORMATTER)
	private Date proTime;

	/**
	 * 工控机的生产线id,注意和controlInvoiceNo区别,
	 * 此id为表的自增长id
	 * 部分工控prodId和controlInvoiceNo为同一个
	 */
	private Long prodId;

	/**
	 * 生产线
	 */
	private Long lineId;

	/**
	 * 生产线名
	 */
	@ExcelCell(value = "生产线名", sort = 21)
	private String lineName;

	/**
	 * 工控机发货单号,用于工控机发货单盘关联的数据
	 */
	@ExcelCell(value = "发货单号", sort = 22)
	private String controlInvoiceNo;

	/**
	 * 工控机的备注
	 */
	@ExcelCell(value = "备注", sort = 23)
	private String controlRemark;

	/**
	 * 是否自主生产,1表示是工控机自己生产的
	 */
	private Integer conAuto;

	/**
	 * 是否关联erp,只有手动生产的才会有此数据
	 */
	private Integer linkErp;

	/**
	 * 任务单号
	 */
	private String indentCode;

	@ExcelCell(value = "是否手动", sort = 24)
	@TableField(exist = false)
	private String conAutoTxt;

	@TableField(exist = false)
	@ExcelCell(value = "是否关联ERP", sort = 25)
	private String linkErpTxt;

	public String getConAutoTxt() {
		if (conAuto == null || !conAuto.equals(1)) {
			return "自动";
		} else {
			return "手动";
		}
	}

	public String getLinkErpTxt() {
		if (conAuto == null || !conAuto.equals(1)) {
			//	自动生产
			return "";
		}
		if (linkErp != null && linkErp.equals(1)) {
			return "已关联";
		} else {
			return "未关联";
		}
	}

	/**
	 * 工控机生产方量
	 */
	@TableField(exist = false)
	private Double proStere;

	public Double getProStere() {
		//	判定是砼还是砂浆
		Double concreteStere = getConcreteStere();
		if (concreteStere != null && concreteStere > 0) {
			proStere = concreteStere;
		} else {
			proStere = getMortarStere();
		}
		return proStere;
	}

	/**
	 * 关联的erp派单表的id
	 */
	public Long erpId;
}
